package Network;

/**
 * La classe ServerTCP initie <br>
 * Les Listener des boutons se trouvent dans la classe: MainFrameListener
 * @author Romain Bustos
 * @author Matthieu Perrin
 * @version 1.0
 */

import chataudio.Constant;
import controleur.AbstractChatControleur;
import java.net.*;

public class ServerTCP extends Thread {
    private AbstractChatControleur control;
   private ServerSocket arrayServer;
   private boolean running = true;

   public ServerTCP(AbstractChatControleur controleur) throws Exception {
       this.control = controleur;
       try{
        arrayServer = new ServerSocket(Constant.tcpPort);
        System.out.println("Server listening on port 4000.");           
       }
       catch(Exception e){ 
           arrayServer = new ServerSocket(4001);
       }
   } 
   
   public void StartServer(){
       this.start();
   }

    @Override
   public void run() {
        // ---- DEBUT BOUCLE THREAD ----
        while (running) {
            try {
                System.out.println("Waiting for connections.");
                //Socket client = arrayServer.accept();
                //Socket client;
                //System.out.println("Accepted a connection from: " + client.getInetAddress());
               // ThreadServerTCP c = new ThreadServerTCP(arrayServer, control);
               // c.StartConnection();
            } catch (Exception e) {
            }

        }
        // ---- FIN BOUCLE THREAD ----
    }
    
}
